package com.zhuojy.equity.mall.admin.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhuojy.equity.mall.admin.common.entity.TMoney;
import com.zhuojy.equity.mall.admin.common.entity.TPosition;
import com.zhuojy.equity.mall.admin.common.entity.TUser;
import com.zhuojy.equity.mall.admin.common.entity.vo.TMoneyVO;
import com.zhuojy.equity.mall.admin.common.pojo.JsonResult;
import com.zhuojy.equity.mall.admin.dal.mapper.TMoneyMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class TMoneyService extends ServiceImpl<TMoneyMapper, TMoney> {
    @Autowired
    private UserService userService;
    @Autowired
    private PositionService positionService;
    /**
     * 应收款条查分页
     * @param tMoney
     * @param pageNum
     * @param pageSize
     * @return
     */
    public JsonResult findTMoneyPagination(TMoney tMoney, Integer pageNum, Integer pageSize) {
        Page<TMoney> page = new Page<>(pageNum,pageSize);
        IPage<TMoney> tMoneyIPage = this.baseMapper.findTMoneyPagination(tMoney,page);
        return JsonResult.success(tMoneyIPage.getRecords(),tMoneyIPage.getTotal());
    }

    /**
     * 应收款回显
     * @param id
     * @return
     */
    public TMoneyVO findTMoneyById(Long id) {
       TMoney tMoney = this.baseMapper.selectById(id);
       TUser tUser = userService.getById(tMoney.getUserId());
       TPosition tPosition = positionService.getById(tMoney.getDeptId());
        TMoneyVO tMoneyVO = new TMoneyVO();
        BeanUtils.copyProperties(tMoney,tMoneyVO);
        BeanUtils.copyProperties(tUser,tMoneyVO);
        BeanUtils.copyProperties(tPosition,tMoneyVO);
        System.out.println(tMoneyVO);
        return tMoneyVO;
    }

    /**
     * 应收款删除
     * @param id
     */
    public void deleteTMonyById(Long id) {
        this.baseMapper.deleteById(id);
    }

    /**
     * 收款明细-类型条查-动态下拉
     * @return
     */
    public List<TMoney> findOptions() {
       return this.baseMapper.findOptions();
    }
}
